<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${package.Mapper}.${table.mapperName}">



    <sql id="columns">
        <#assign columnField>
            <#list table.fields as column>
                ${column.name} as ${column.propertyName},
            </#list>
        </#assign>
             ${columnField?substring(0, columnField?last_index_of(","))}
    </sql>


    <sql id="where">
        <trim prefix="WHERE" prefixOverrides="AND">
            <#list table.fields as column>
                <#if  column.propertyType == "String">
                 <if test=" ${column.propertyName} !=null and ${column.propertyName} != ''">
                     AND  ${column.name}= ${"#"}{${column.propertyName}}
                 </if>
                <#else >
                 <if test=" ${column.propertyName} !=null   ">
                     AND  ${column.name}= ${"#"}{${column.propertyName}}
                 </if>
                </#if>
            </#list>
        </trim>
    </sql>

    <select id="selectList" parameterType="${entity}" resultType="${entity}">
        select
        <include refid="columns"/>
        from ${table.name}
        <include refid="where" />
    </select>

    <update id="update${entity}" parameterType="${entity}">
        UPDATE ${table.name}
        <trim prefix="WHERE" suffixOverrides=",">
            <#list table.fields as column>
                   <#if  column.propertyType == "String">
                <if test=" ${column.propertyName} !=null and ${column.propertyName} != ''">
                    ${column.name}=${"#"}{${column.propertyName}},
                </if>
                   <#else >
                 <if test=" ${column.propertyName} !=null  ">
                     ${column.name}=${"#"}{${column.propertyName}},
                 </if>
                 </#if>
            </#list>
        </trim>
        WHERE <#list table.fields as column>    <#if column.keyFlag >  ${column.name}=${"#"}{${column.propertyName}} </#if> </#list>
    </update>

    <delete id="delete${entity}" parameterType="java.lang.String">
        delete from ${table.name}
        WHERE  <#list table.fields as column>  <#if column.keyFlag == true>${column.name}=${"#"}{id}</#if></#list>
    </delete>

</mapper>